home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
assemblr
/
library
/
edit
/
fremacsr
/
z100.asm
< prev
Wrap
Assembly Source File
|
1987-03-16
|
12KB
|
601 lines
;History:52,1
page ,132
comment /
Porting EMACS and Percival to MS-DOS computers other than the Z-100:
This entire file (Z-100.ASM) needs to be re-written, since it contains
all the Z-100 dependencies. The following conventions must be maintained:
1) Never leave this module with DF=1.
2) Never destroy ES.
3) Never MOV AX,DATA, always use the copy in the appropriate segment register.
4) Return NC if a routine succeeds, or fulfills its goals.
/
.xlist
include memory.def
;the only bios call is used by check_for_key
bios_seg segment at 40h
org 27*3
bios_confunc label far
bios_seg ends
data segment byte public
public max_screen_line
max_screen_line db 22 ;number of last text row on screen.
fontptr dd 6fh
;the following font pointers point to a font containing the 96 printable
; characters, with the exception of the first which also contains graphics.
; The first font is numbered zero, and has all the Zedit funnies. The
; second font uses the first_font, but does inverse video for the high bit
; characters. The third font and on use the normal control character font to
; print controls. The last font is the internal font, and is used to print
; control chars, etc.
first_font dw ?,? ;fonts zero and one.
controls_ptr label word ;font eight.
dw controls,?
controls label byte
include control.asm
public scan_lines_per_char
scan_lines_per_char db 9 ;used to convert pixel position into character position.
shifted equ 40h
key_names label byte
db ',','Comma',0
db '(','LPar',0
db ')','RPar',0
db 7fh,'Delete',0
db 0a3h+shifted,'D Chr',0
db 0a3h,'I Chr',0
db 0a4h+shifted,'Del Line',0
db 0a4h,'Ins Line',0
db -1,'Timeout',0
db -2,'Left Down',0 ;mouse button key names.
db -3,'Right Down',0
db -4,'Left Up',0
db -5,'Right Up',0
db -6,'Middle Down',0
if 0
db -7,'Middle Up',0
endif
db 0
key_shifted label byte
db 08Dh,'Enter',0
db 095h,'Help',0
db 096h,'F0',0
db 097h,'F1',0
db 098h,'F2',0
db 099h,'F3',0
db 09Ah,'F4',0
db 09Bh,'F5',0
db 09Ch,'F6',0
db 09Dh,'F7',0
db 09Eh,'F8',0
db 09Fh,'F9',0
db 0A0h,'F10',0
db 0A1h,'F11',0
db 0A2h,'F12',0
db 0A5h,'Up Arrow',0
db 0A6h,'Down Arrow',0
db 0A7h,'Right Arrow',0
db 0A8h,'Left Arrow',0
db 0A9h,'Home',0
db 0AAh,'Break',0
db 0ADh,'KP-',0
db 0AEh,'KP.',0
db 0B0h,'KP0',0
db 0B1h,'KP1',0
db 0B2h,'KP2',0
db 0B3h,'KP3',0
db 0B4h,'KP4',0
db 0B5h,'KP5',0
db 0B6h,'KP6',0
db 0B7h,'KP7',0
db 0B8h,'KP8',0
db 0B9h,'KP9',0
db 0,'Unknown',0
key_buffer label byte
db 12 dup(?)
extrn inversing: word
color_xlat db 0, 1, 4, 5, 2, 3, 6, 7
;a character must be chosen which causes the idling string to be reloaded.
; this one is shift-help.
public breakchar
breakchar dw 0d5h
data ends
bios_seg segment at 40h
org 9h
bios_conout label far
bios_seg ends
code segment byte public
assume cs:code, ds:data, es:nothing
;all of the code in this segment is called with the above assumes.
printchar:
call bios_conout
ret
public init_entry
init_entry:
;called when entering. May destroy any but seg-regs.
push es
xor ax,ax
mov es,ax
mov ax,es:3feh ;the monitor segment
mov word ptr fontptr+2,ax
les si,fontptr
mov ax,es:[si]
mov first_font,ax
mov bx,es:[si+2]
mov first_font+2,bx
pop es
mov controls_ptr+2,ds
mov al,'y' ;disable key expansion
call printesc
mov al,'?'
call printchar
mov al,'y'
call printesc
mov al,'1'
call printchar
mov al,'x'
call printesc
mov al,'1'
call printchar
mov dx,0*256 + 49 ;try to put the cursor way down low.
call position_cursor
push ds ;see if it got there.
xor ax,ax
mov ds,ax
mov ds,ds:[3feh]
mov al,ds:[292h]
pop ds
cmp al,49 ;go if it didn't
jne init_entry_1
mov max_screen_line,47 ;it did - remember the last scrollable line.
init_entry_1:
ret
public uninit_exit
uninit_exit:
;called when exiting. May destroy any but seg-regs.
call restore_font
mov al,'x' ;enable key expansion
call printesc
mov al,'?'
call printchar
mov al,'y' ;disable the 25th line.
call printesc
mov al,'1'
call printchar
mov dh,0 ;put the cursor on the last scrollable line.
mov dl,max_screen_line
inc dl
call position_cursor
ret
restore_font:
push es
les si,fontptr
mov ax,first_font
mov es:[si],ax
mov ax,first_font+2
mov es:[si+2],ax
pop es
ret
public check_for_key
check_for_key:
;return zr if no key is waiting.
;return nz,ax=key if a key is waiting, but don't input the key yet.
push bx ; Save regs
push di
push si
push dx
push ax
mov ah,4 ; get look function
call bios_confunc ; get copy of first char in queue, empty?
mov bl,0 ; assume queue empty, was it ?
jc check_for_key_1 ; yes, skip
mov bl,al ; no, save char
check_for_key_1:
mov al,0ffh ; get -1
adc al,0 ; set 'z' flag appropriately
pop ax ; recover ax
mov al,bl ; get char
pop dx ; restore regs
pop si
pop di
pop bx
mov ah,0
ret
public get_key_value
get_key_value:
mov ah,7
int 21h
mov ah,0
ret
public decode_key
decode_key:
;enter with al=key value.
;exit with si,cx -> the key's name in ASCII.
mov di,offset key_buffer
mov ah,al
mov si,offset key_names
call decode_search ;search for the literal names.
jne decode_key_1
mov si,offset key_shifted ;search for the unshifted versions.
call decode_search
jne decode_key_1
mov al,'s'
stosb
push ax ;save the key's value.
and ah,not shifted ;search for the shifted versions.
mov si,offset key_shifted ;search for the unshifted versions.
call decode_search
pop ax
jne decode_key_1
dec di ;remove the 's'.
mov al,ah
cmp al,' ' ;control char?
jb decode_key_3 ;yes.
stosb ;no - just return the char.
jmp decode_key_2
decode_key_3:
mov word ptr [di],'C' + '-'*256
add di,2
add al,'@'
stosb
jmp decode_key_2
decode_key_1:
lodsb ;copy to the next null.
stosb
or al,al
jne decode_key_1
dec di ;don't include the null.
decode_key_2:
mov si,offset key_buffer
mov cx,di
sub cx,si
ret
decode_search:
;enter with ah=key to search for, si->table.
;exit with al=key, nz if found, al=0, zr if not found.
lodsb
or al,al ;end of table?
je decode_search_2 ;yes - try shifted values.
cmp al,ah ;is this the key?
je decode_search_2 ;yes.
decode_search_1:
lodsb ;skip to the next null.
or al,al
jne decode_search_1
jmp decode_search
decode_search_2:
or al,al
ret
printesc:
;print an escape followed by the char in al.
push ax
mov al,ESC
call printchar
pop ax
call printchar
ret
public ring_the_bell
ring_the_bell:
mov al,'G'-40h
call printchar
ret
code ends
code segment byte public
assume cs:code, ds:nothing, es:data
;all of the code in this segment is called with the above assumes.
public position_cursor
position_cursor:
;enter with dh=col (0...80), dl=row (0..max_screen_line)
;exit with cursor set to that position.
mov al,'Y'
call printesc
mov al,dl
add al,' '
call printchar
mov al,dh
add al,' '
call printchar
ret
public solid_cursor
solid_cursor:
mov al,'x'
call printesc
mov al,';'
call printchar
ret
public blink_cursor
blink_cursor:
mov al,'y'
call printesc
mov al,';'
call printchar
ret
public block_cursor
block_cursor:
mov al,'x'
call printesc
mov al,'4'
call printchar
ret
public underscore_cursor
underscore_cursor:
mov al,'y'
call printesc
mov al,'4'
call printchar
ret
public set_screen_color
set_screen_color:
;enter with al=fore color, ah=back color
push ax
mov al,'m'
call printesc
pop ax
mov bx,offset color_xlat
xlat
add al,'0' ;print the fore color number.
call printchar
mov al,ah ;print the back color number.
xlat
add al,'0'
call printchar
ret
public move_line
move_line:
;enter with dl=source row, al=destination row.
push ax
push bx
push cx
push dx
push si
push di
push bp
push es
push ds
;start pushing mtr_mdl parameters
push dx ;source line.
push ax ;destination line.
xor ax,ax
mov ds,ax
mov ds,ds:3feh ;the monitor segment
call dword ptr ds:[77h] ;mtr_mdl
pop ds
pop es
pop bp
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
public clear_to_eol
clear_to_eol:
;enter with dl=current row, dh=current column.
push bx
mov bl,80
call clear_count
pop bx
ret
public clear_count
clear_count:
;enter with dl=current row, dh=current column, bl=column to clear to.
cmp dh,bl ;already past it?
jae clear_count_1 ;yes.
push ax
push bx
push cx
push dx
push si
push di
push bp
push es
push ds
;start pushing edc parameters.
push dx ;push row,
xchg dl,dh
push dx ;push col.
sub bl,dl
push bx ;push count of columns to clear.
xor ax,ax
mov ds,ax
mov ds,ds:3feh ;the monitor segment
call dword ptr ds:[67h] ;mtr_edl
pop ds
pop es
pop bp
pop di
pop si ;restore saved registers.
pop dx
pop cx
pop bx
pop ax
clear_count_1:
ret
public xychrout
xychrout:
;enter with dh=col, dl=row, al=character to print, ah=font to print it in.
push ax ;save everything that we might need.
push bx
push cx
push dx
push di
push si
push es
push ds
cmp dh,80 ;past the right margin?
jae xychrout_3 ;yes - don't print.
mov si,offset first_font
cmp ah,0 ;font zero?
jne xychrout_5 ;no - print specially.
mov bx,0 ;assume no inverse video
cmp al,80h-'^'+7fh
jb xychrout_1 ;print all normal chars normally.
jmp short xychrout_0
xychrout_5:
mov si,offset controls_ptr
xor bx,bx ;assume no inverse video.
or al,al ;high bit set?
jns xychrout_1 ;no - no inverse video.
xychrout_0:
not bx
and al,7fh
xychrout_1:
xor bx,inversing ;set the inverse video flag.
cmp al,' ' ;print controls specially.
jb xychrout_2
cmp al,7fh ;print delete specially.
je xychrout_4
sub al,' '
jmp short xychrout_6
xychrout_4:
sub al,7fh-2fh ;convert del to proper index in control font.
xychrout_2:
mov si,offset controls_ptr
xychrout_6:
mov cx,es ;ensure that ds:si ->font pointer.
mov ds,cx
les di,fontptr
movsw
movsw
push ds
;push four words as parameters to mtr_dfc
xchg dh,dl
push dx ;push col first
xchg dh,dl
push dx ;push row next.
push ax ;push font index.
push bx ;push inverse video flag.
xor ax,ax
mov ds,ax
mov ds,ds:3feh ;the monitor segment
call dword ptr ds:[5fh] ;mtr_dfc
pop ds
call restore_font
xychrout_3:
pop ds
pop es
pop si
pop di
pop dx
pop cx
pop bx
pop ax
ret
public hardware_roll_down
hardware_roll_down:
;exit: if this machine is capable of hardware roll, do it and exit with cy=0,
; otherwise, exit with cy=1. The hardware roll must leave the last line
; on the screen as the last line.
;preserve bx.
push dx
mov al,max_screen_line ;move the lower status line up.
mov dl,al
inc dl
call move_line ;dl=source, al=dest.
pop dx
mov al,'H' ;home up.
call printesc
mov al,'I' ;reverse index.
call printesc
clc
ret
public hardware_roll_up
hardware_roll_up:
;exit: if this machine is capable of hardware roll, do it and exit with cy=0,
; otherwise, exit with cy=1. The hardware roll must leave the last line
; on the screen as the last line.
;preserve bx.
push dx
mov dl,max_screen_line
inc dl
mov dh,0
call position_cursor
mov al,LF ;roll the screen up.
call printchar
mov al,max_screen_line ;move the lower status line up.
mov dl,al
dec dl
call move_line ;dl=source, al=dest.
pop dx
clc
ret
code ends
end